<template>
  <layout>
    <div class='search'>
      <el-input  placeholder="请输入内容"></el-input>
      <el-button type="info"  @click="$router.push('/brand/create')" v-if="$checkPermission(26)">新增品牌</el-button>
    </div>
    <div>
      <el-table
    :data="tableData"

    style="width: 100%"
    >
    <el-table-column type="selection" width="55"></el-table-column>
    <el-table-column  prop="id" label="ID" width="120"></el-table-column>
    <el-table-column prop="create_time" label="创建时间" ></el-table-column>
     <el-table-column prop="name" label="姓名" show-overflow-tooltip></el-table-column>
     <el-table-column fixed='right' label="操作 "show-overflow-tooltip>
     <template slot-scope="scope">
        <el-button size="mini"
              @click="handleAd(scope.$index, scope.row)">权限</el-button>
        <el-button size="mini"
              @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button size="mini" type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template slot-scope="scope">
    </el-table-column>
    
  </el-table>
    </div>
  </layout>
</template>

<script>
export default {
  data() {
    return {
      tableData: [{
          
        }, {
          
        },
        ],
    }
  },
  methods: {
    handleAd(index,row){
      console.log(index, row);
    },
    handleEdit(index, row) {
        console.log(index, row);
      },

    //前后端数据同时删除
    handleDelete(index, row) {

      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http.post('/brand/trash',{
          id : row.id
        }).then( res =>{
          this.tableData.splice(index,1)
        })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });

        
      }
  },

  //调取数据
  created() {
    this.$http.get('/brand/select').then( res =>{
      if(res.errcode == 0){
        this.tableData = res.data
      }
    })
  },
}
</script>

<style >
  .search{
    display:flex;
    padding:10px;
    justify-content:space-between;
  }
  .el-input{
    width:180px;
  }
  
</style>